<!-- Modal -->
<div class="modal fade " id="addCustomerInfoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">企业信息维护</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">企业名称</label>
                        <div class="col-sm-7">
                            <input id="addCustomerInfoModal_custName" type="text" class="form-control"
                                   style="width: 100%;"
                                   disabled="disabled">
                            <input id="addCustomerInfoModal_custId" type="hidden">
                        </div>
                        <button id="changeEnterTypeBtn" type="button" class="btn btn-primary"   onclick="changeEnterType()">切换</button>
                    </div>
                    <div class="form-group" id="windCodeDiv" >
                        <label for="inputEmail3" class="col-sm-2 control-label">WIND代码</label>
                        <div class="col-sm-7">
                            <input id="addCustomerInfoModal_windCode" type="text" class="form-control"
                                   onchange="queryCustNameByWindCode()">
                        </div>
                        <div id="addCustomerInfoModal_msg" class="col-sm-3" style="color: red;">
                        </div>
                    </div>
                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">是否城投</label>
                        <div class="col-sm-7">
                            <div id="statusDiv" class="radio col-sm-6">
                                <label>
                                    <input type="radio" name="addCustomerInfoModal_isCityInvest" value="1">
                                    是
                                </label>
                                <label>&nbsp;</label>
                                <label><input type="radio" name="addCustomerInfoModal_isCityInvest" value="0">不是</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">外部环境</label>
                        <div class="col-sm-7">
                            <textarea class="form-control" id="addCustomerInfoModal_externalEnvironment">

                            </textarea>
                        </div>
                    </div>
                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">业务经营</label>
                        <div class="col-sm-7">
                            <textarea class="form-control" id="addCustomerInfoModal_businessOperation">

                            </textarea>
                        </div>
                    </div>
                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">财务表现</label>
                        <div class="col-sm-7">
                            <textarea class="form-control" id="addCustomerInfoModal_financialPerformance">

                            </textarea>
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary pull-right"
                            onclick="saveCustomerInfo()">保存
                    </button>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>

<script>
    function changeEnterType() {
        var type = $("#addCustomerInfoModal_custName").attr("disabled") ;
        if(undefined == type) {
            $("#addCustomerInfoModal_custName").attr("disabled","disabled") ;
            $("#addCustomerInfoModal_custName").val("");
            $("#addCustomerInfoModal_windCode").removeAttr("disabled") ;
        } else {
            $("#addCustomerInfoModal_custName").removeAttr("disabled") ;
            $("#addCustomerInfoModal_windCode").val("");
            $("#addCustomerInfoModal_windCode").attr("disabled","disabled") ;
        }
    }
    function queryCustNameByWindCode() {
        var windCode = $("#addCustomerInfoModal_windCode").val();
        $("#addCustomerInfoModal_msg").html("");
        if (windCode == null || windCode == "" || windCode.trim() == "") {
            return;
        }
        var url = "/scorebasicdata/cust/querycompanyname?windCode=" + windCode;
        $("#btnSubmit").attr("disabled", "disabled");

        getReq(url, function (result) {
            if (result.success) {

                $("#addCustomerInfoModal_custName").val(result.msg);
            } else {
                $("#addCustomerInfoModal_msg").html(result.msg);
            }
            $("#btnSubmit").removeAttr("disabled");
        });

    }

    function customerInfoModelInit() {
        $("#windCodeDiv").css("display","block");
        $("#changeEnterTypeBtn").css("display","block");
        $("#addCustomerInfoModal_windCode").val("");
        $("#addCustomerInfoModal_msg").html("");
        $("#addCustomerInfoModal_windCode").removeAttr("disabled");
        $("#addCustomerInfoModal_custId").val("");
        $("#addCustomerInfoModal_custName").val("");
        $("input[name='addCustomerInfoModal_isCityInvest'][value='0']").attr("checked", 'true');
        $("#addCustomerInfoModal_externalEnvironment").val("");
        $("#addCustomerInfoModal_businessOperation").val("");
        $("#addCustomerInfoModal_financialPerformance").val("");
    }

    function customerInfoModelSetValue(index) {
        $("#windCodeDiv").css("display","none");
        $("#changeEnterTypeBtn").css("display","none");
        $("#addCustomerInfoModal_custName").attr("disabled","disabled") ;
        var options = $("#table1").bootstrapTable("getData");
        var row = options[index];
        var url = "/scorebasicdata/cust/info?issuerId=" + row.id;
        getReq(url,function (result) {
            if(result.length != 0) {
                var data = result[0] ;
                $("#addCustomerInfoModal_custId").val(data.id);
                $("#addCustomerInfoModal_custName").val(data.custName);
                $("input[name='addCustomerInfoModal_isCityInvest'][value='" + data.isCityInvest + "']").attr("checked", 'true');
                $("#addCustomerInfoModal_externalEnvironment").val(data.externalEnvironment);
                $("#addCustomerInfoModal_businessOperation").val(data.businessOperation);
                $("#addCustomerInfoModal_financialPerformance").val(data.financialPerformance);
            }
        });

    }


    function saveCustomerInfo() {
        var data = {
            id: $("#addCustomerInfoModal_custId").val(),
            custName: $("#addCustomerInfoModal_custName").val(),
            windCode: $("#addCustomerInfoModal_windCode").val(),
            isCityInvest: $("input[name=addCustomerInfoModal_isCityInvest]:checked").val(),
            externalEnvironment: $("#addCustomerInfoModal_externalEnvironment").val(),
            businessOperation: $("#addCustomerInfoModal_businessOperation").val(),
            financialPerformance: $("#addCustomerInfoModal_financialPerformance").val()
        };
        var url = "/scorebasicdata/cust/save";
        postReq(url, data, function (result) {
            if (result.success) {
                toastr['success']('操作成功', '提示');
                $("#table1").bootstrapTable("refresh");
                $("#addCustomerInfoModal").modal("hide");
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
